#ifndef __CONFIG_H
#define __CONFIG_H

#include <Preferences.h>

#define KEY_MOUDULE_NAME "module_name"
#define KEY_DEV_NAME "dev_name"
#define KEY_DEV_PWD1 "dev_pwd1"
#define KEY_DEV_PWD2 "dev_pwd2"
#define KEY_DEV_PWD3 "dev_pwd3"
#define KEY_HTTPS_CERT "https_cert"



#define KEY_WIFI_SSID   "wifi_ssid"
#define KEY_WIFI_PWD    "wifi_pwd"
#define KEY_WIFI_MODE   "wifi_mode"
#define KEY_WIFI_IP     "wifi_ip"
#define KEY_WIFI_SUBNET "wifi_subnet"
#define KEY_WIFI_GW     "wifi_gw"

#define KEY_DNS1        "dns0"
#define KEY_DNS2        "dns1"
#define KEY_MQTT_EN     "mqtt_en"
#define KEY_MQTT_INTERVAL   "mqtt_interval"
#define KEY_MQTT_URL   "mqtt_url"
#define KEY_MQTT_NAME   "mqtt_name"
#define KEY_MQTT_PWD    "mqtt_pwd"
#define KEY_MQTT_CERT    "mqtt_cert"


#define KEY_NTP_SERVER    "ntp_server"



extern Preferences prefs;

extern int gLedState;
extern unsigned char cali_default_table[];
class Config
{
public:
    Config();
    void begin();
    void clear();
    void load_default();


    void set_module_name(String value);
    String get_module_name();

    void set_dev_name(String value);
    String get_dev_name();

    void set_dev_pwd1(String value);
    String get_dev_pwd1();

    void set_dev_pwd2(String value);
    String get_dev_pwd2();

    void set_dev_pwd3(String value);
    String get_dev_pwd3();

    void set_https_cert(String value);
    String get_https_cert();


    void set_cali_cnt(uint16_t value);
    uint16_t get_cali_cnt();
    void set_cali_mode(uint16_t value);
    uint16_t get_cali_mode();


    
    void set_wifi_ssid(String value);
    String get_wifi_ssid();
    void set_wifi_pwd(String value);
    String get_wifi_pwd();

    
    void set_wifi_mode(uint16_t value);
    uint16_t get_wifi_mode();
    void set_wifi_ip(IPAddress p);
    IPAddress get_wifi_ip();
    void set_wifi_subnet(IPAddress p);
    IPAddress get_wifi_subnet();
    void set_wifi_gw(IPAddress p);
    IPAddress get_wifi_gw();
    void set_dns(uint8_t index, IPAddress p);
    IPAddress get_dns(uint8_t index);


    void set_mqtt_en(uint16_t value);
    uint16_t get_mqtt_en();
    void set_mqtt_interval(uint16_t value);
    uint16_t get_mqtt_interval();    
    void set_mqtt_url(String value);
    String get_mqtt_url();
    String get_mqtt_server();
    uint16_t get_mqtt_port();
    void set_mqtt_name(String value);
    String get_mqtt_name();
    void set_mqtt_pwd(String value);
    String get_mqtt_pwd();

    void set_mqtt_cert(String value);
    String get_mqtt_cert();



    void set_ntp_server(String value);
    String get_ntp_server();

private:
    String module_name;
    String dev_name;
    String dev_pwd1;
    String dev_pwd2;
    String dev_pwd3;
    String https_cert;


//网络相关/////////////////////////////////
//wifi/////////////////////////////////
    String      wifi_ssid;
    String      wifi_pwd;
    uint16_t    wifi_mode;//0:Auto; 1:Static; 2:Disable
    IPAddress   wifi_ip;
    IPAddress   wifi_subnet;
    IPAddress   wifi_gw;

//mqtt/////////////////////////////////
    uint16_t mqtt_en;
    uint16_t mqtt_interval;
    String mqtt_url;
    String mqtt_name;
    String mqtt_pwd;
    String  mqtt_cert;

    String ntp_server;

    IPAddress    dns[4];

/////////////////////////////////////////


};
extern Config config;

#endif